package mybatis;

import mybatis.dao.EmployeeMapper;
import mybatis.yang.Book;
import mybatis.yang.Books;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class testDao {

    public static void main(String [] args){

        try{
            String resource = "Conf/mybatis-config.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            List<Book> list=new ArrayList<Book>();
            SqlSessionFactory sqlSessionFactory= new SqlSessionFactoryBuilder().build(inputStream);
            SqlSession openSession=sqlSessionFactory.openSession();

            EmployeeMapper mapper=openSession.getMapper(EmployeeMapper.class);
            Books book=new Books();
            book=mapper.selectbook();
            System.out.println(book);
            System.out.println(book.getProduct_name());
            openSession.commit();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
        }
    }
}
